import { createSlice } from "@reduxjs/toolkit";
import { UserInfoResponseType } from "@/api/user/type-user";

interface initialStateType {
  userInfo: UserInfoResponseType | null;
  countBalance: number;
}
const initialState: initialStateType = {
  userInfo: null,
  countBalance: 0,
};

// 创建一个Slice
export const homeSlice = createSlice({
  name: "home",
  initialState,
  reducers: {
    setUserInfo: (state, action) => {
      console.log(action, "action");
      return {
        ...state,
        userInfo: action.payload,
      };
    },
    setCountBalance: (state, action) => {
      return {
        ...state,
        countBalance: action.payload,
      };
    },

  },
});

// 导出加减方法
export const { setUserInfo, setCountBalance } = homeSlice.actions;

// 暴露reducer
export default homeSlice.reducer;
